<form action="#" class="am-form" style="margin-top: 20px;">
    <fieldset>
        <legend>单期限额</legend>
        <div class="form_content">
            <div class="input">
                <input type="number" class="am-form-field game-max" placeholder="最大限额">
            </div>
            <div class="button">
                <button type="button" class="am-btn am-btn-primary btn-issue-limit">保存</button>
            </div>
            <div class="clear"></div>
            <div class="clue">说明：不填或者填写0表示不限制，下同。</div>
        </div>

        <legend>单注限额(快速设置)</legend>
        <div class="form_content">
            <div class="input">
                <input type="number" class="am-form-field quick-min" placeholder="最小限额" style="float: left; width: 49%;">
                <input type="number" class="am-form-field quick-max" placeholder="最大限额" style="float: left; width: 49%; margin-left: 2%;">
            </div>
            <div class="button">
                <button type="button" class="am-btn am-btn-primary btn-quick">快速设置</button>
            </div>
            <div class="clear"></div>
        </div>
    </fieldset>
</form>

<div class="game-detail">
</div>
<style text="text/css">
    .am-input-group .am-form-field {
        height: 22px;
    }
</style>

<script>
    var loadGameF = function() {
        var game = GroupUtil.group.lottery;

        // 载入相关的游戏设置页面
        switch_page("limit/" + game + "_limit", $(".game-detail"), function() {
            // 关注tab的点击效果
            var arr = $(".am-tabs-nav li");
            var register_tab_index = function(tab, index) {
                tab.click(function() {
                    $('.am-tabs').tabs('open', index);
                })
            }
            for (var i = 0; i < arr.length; i++) register_tab_index($(arr[i]), i);

            AdminLimit.init(game, Util.getGameRule(game));
        });
    };
    GroupUtil.init(false, function() {
        loadGameF(GroupUtil.group.lottery);
    });

    function setAllLimit(v, isMin) {
        // 取得当前选中的tab标签
        var arr = $(".am-tabs-bd .am-tab-panel");
        for (var i = 0; i < arr.length; i++) {
            var tab = $(arr[i]);
            if (tab.attr("class").indexOf("am-active") != -1) {
                var inputs = tab.find(isMin ? "input.min" : "input.max");
                inputs.val(v);
            }
        }
    }

    $(".btn-quick").click(function() {
        setAllLimit($(".quick-min").val(), true);
        setAllLimit($(".quick-max").val(), false);
    });
    $(".btn-issue-limit").click(function() {
        var v = $(".game-max").val().trim();
        if (v == '') {
            alert2("请填入最大单期限额的金额（单位：元）！");
            return;
        }

        v = parseInt(v);
        if (v < 0) {
            alert2("最大限额应该大于0！");
            return;
        }

        CMD.group_lottery_rate_ranges(GroupUtil.group.lottery, GroupUtil.group.id, {
            targets: "0," + (v * 100),
        }, function() {
            alert2("修改完成！");
        });
    });
</script>
